<template>
  <DialogSubmitForm v-bind="formFrame" ref="form" />
</template>
<script setup lang="ts">
import { MDialogSubmitForm as DialogSubmitForm } from "page-com";
import { shallowReactive, useTemplateRef } from "vue";
import { updateService } from "@/api/product/serviceApi";
import { DialogSubmitFormFrame, DialogSubmitFormInstance } from "page-com";
import { successMsg } from "@/utils/message";
import { uploadFun } from "@/utils/utils";
const form = useTemplateRef<DialogSubmitFormInstance>("form");
const formFrame = shallowReactive<DialogSubmitFormFrame>({
  submitFun: async function (data) {
    let res = await updateService(data);
    if (res.code == RESPONSE_CODE.SUCCESS) {
      successMsg("修改成功");
      emit("saveSuccess", data);
      form.value.hide();
    }
  },
  width: "400px",
  items: [
    {
      frameType: "input",
      key: "serviceName",
      label: "服务名称",
      validations: {
        required: true
      }
    },
    {
      frameType: "input",
      type: "textarea",
      key: "serviceDesc",
      label: "服务描述",
      validations: {
        required: true
      }
    },
    {
      label: "服务图片",
      frameType: "singleUpload",
      key: "serviceImage",
      tips: "最大28px X 28px",
      uploadUrl: "/user/uploadFile",
      uploadFun: uploadFun
    }
  ]
});
function show(vo: ShopServiceVo) {
  form.value.show(vo);
}

defineExpose({ show });
const emit = defineEmits<{
  saveSuccess: [data: ShopServiceVo];
}>();
</script>
